
$(function () {
    var vm, indexlists = [], page = 1, pageSize = 20, islock = true;

    function loadData() {
        if(!page || !islock) return;
        islock = false;
        $.ajax({
            type:'get',
            url : 'http://zt4.oeeee.com/www/ExtraData/getData/db/2017ndjlgzw/pageSize/'+pageSize+'/page/'+page,
            dataType : 'JSONP',
            jsonpCallback : 'jqgz',
            success : function (json) {
                if(json.status==0){
                    var lists = json.data;
                    if(page == 1){
                        for (var i=1;i<4;i++){
                            indexlists.push(lists[i]);
                        }
                        vm = new Vue({
                            el : '#news',
                            data: {
                                lists : lists,
                                indexlists : indexlists
                            }
                        })
                    }else{
                        vm.lists = vm.lists.concat(lists);
                    }
                    // 是否还有下一页
                    if(json.extra.currentPage == json.extra.totalPage){
                        page = false;
                        $('.more-new-btn').hide();
                    }else{
                        page++;
                        $('.more-new-btn').show();
                    }

                    islock = true;
                }
            }
        })
    }

    loadData();

    // 点击加载更多
    $(document).on('click','.more-new-btn',function () {
        loadData();
    })
})